//
//  CZDetailMessage.swift
//  GZWeibo666
//
//  Created by wzz on 15/12/2.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class CZDetailMessage: NSObject {
    /// 评论创建时间
    var created_at: String?
    
    /// 评论ID
    var id: Int = 0
    
    /// 评论内容
    var text: String?
    
    /// 评论来源
    var source: String?
    /// 评论作者用户信息
    var user: CZUser?
    
    ///行高
    var rowHeigth : CGFloat = 0
    
    /// 字典转模型
    init(dict: [String: AnyObject]) {
        super.init()    // 创建对象
        
        setValuesForKeysWithDictionary(dict)
    }
    
    /// KVC字典转模型时,字典的key在模型中找不到对应的属性时会调用,在这个方法里面可以什么都不做
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    ///拦截kvc转模型, 只在当key 为user 的时候, 我自己转
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = CZUser(dict: dict)
            }
            
            return   //一定要返回
        }
        
        super.setValue(value, forKey: key)
    }
    
    /// 打印对象信息
    override var description: String {
        return "created_at: \(created_at), id:\(id), text = \(text), source:\(source), user:\(user)"
    }
}
